Passed
Push — master ( fd33d1...5bbd8e )
by Haruaki
01:41 queued 15s
created

test.js ➔ ... ➔ it(ꞌshould work in buffer modeꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 20
rs 9.75
1
"use strict";
2
3
var path = require("path"),
4
    fs = require("fs"),
5
    assert = require("assert"),
6
    es = require("event-stream"),
7
    gutil = require("gulp-util"),
8
    PassThrough = require("stream").PassThrough,
9
    index = require("../src/index");
10
11
describe("gulp-yaml-include", function () {
12
    it("should work in buffer mode", function (done) {
13
        var stream = index();
14
        var testFile = new gutil.File({
15
                base: __dirname,
16
                cwd: __dirname,
17
                path: path.join(__dirname, 'test.yaml'),
18
                contents: fs.readFileSync(path.join(__dirname, "test.yaml"))
19
            });
20
21
        stream.on("data", function () {
22
            assert.equal("paths:\n  a: b\n", testFile.contents.toString());
23
        });
24
25
        stream.on("end", function () {
26
            done();
27
        });
28
29
        stream.write(testFile);
30
        stream.end();
31
    });
32
33
    it("should work in stream mode", function (done) {
34
        var stream = index();
35
        var testStream = new PassThrough();
36
        var testFile = new gutil.File({
37
            base: __dirname,
38
            cwd: __dirname,
39
            path: path.join(__dirname, 'test.yaml'),
40
            contents: testStream
41
        });
42
        testStream.write(fs.readFileSync(path.join(__dirname, "test.yaml")));
43
        testStream.write(Buffer.from("\n"));
44
        testStream.write(Buffer.from("c: 1"));
45
        testStream.end();
46
47
        stream.on("data", function (newFile) {
48
            newFile.pipe(es.wait(function(err, data) {
49
                assert.equal("paths:\n  a: b\nc: 1\n", data.toString());
50
            }));
51
        });
52
53
        stream.on("end", function () {
54
            done();
55
        });
56
57
        stream.write(testFile);
58
        stream.end();
59
    });
60
61
    it("should let null files pass through", function (done) {
62
        var stream = index(),
63
            n = 0;
64
        stream.pipe(es.through(function (file) {
65
            assert.equal(file.path, "null.yaml");
66
            assert.equal(file.contents,  null);
67
            n++;
68
        }, function () {
69
            assert.equal(n, 1);
70
            done();
71
        }));
72
        stream.write(new gutil.File({
73
            path: "null.yaml",
74
            contents: null
75
         }));
76
        stream.end();
77
    });
78
79
    it("should work subdir inc", function (done) {
80
        var stream = index();
81
        var testFile = new gutil.File({
82
                base: __dirname,
83
                cwd: __dirname,
84
                path: path.join(__dirname, 'base.yaml'),
85
                contents: fs.readFileSync(path.join(__dirname, "base.yaml"))
86
            });
87
88
        stream.on("data", function () {
89
            assert.equal("version: 1\nsub:\n  hoge: fuga\n", testFile.contents.toString());
90
        });
91
92
        stream.on("end", function () {
93
            done();
94
        });
95
96
        stream.write(testFile);
97
        stream.end();
98
    });
99
});
100